package com.ph.irp.base.assistantmaterial.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

import com.ph.irp.base.assistantmaterial.service.PBaseAssistantmaterialSuppliercategoryService;
import com.ph.irp.model.PBaseAssistantmaterialSuppliercategory;

public class AssistantmaterialSuppliercategoryAction extends ActionSupport {
	private PBaseAssistantmaterialSuppliercategory suppliercategoryModel = null;
	private Object[] rowlist = null;
	private List<PBaseAssistantmaterialSuppliercategory> suppliercategoryList = null;
	private PBaseAssistantmaterialSuppliercategoryService suppliercategoryService = null;
	public String showSuppliercategoryList() throws Throwable{
		this.suppliercategoryList = this.suppliercategoryService.getALLAssistantmaterialSuppliercategory();
		this.suppliercategoryModel = null;
		return "success";
	}
	public String getSuppliercategoryByCondition() throws Throwable{
		if(suppliercategoryModel == null)
			{
				this.suppliercategoryList = this.suppliercategoryService.getALLAssistantmaterialSuppliercategory();
			}
		else {
				if(!suppliercategoryModel.getSupplierCategoryCode().trim().equals("") && suppliercategoryModel.getSupplierCategoryName().trim().equals("")){
					this.suppliercategoryList = this.suppliercategoryService.getAssistantmaterialSuppliercategoryByCode(suppliercategoryModel.getSupplierCategoryCode().trim());
				}
				else if(!suppliercategoryModel.getSupplierCategoryName().trim().equals("") && suppliercategoryModel.getSupplierCategoryCode().trim().equals("")){
					this.suppliercategoryList = this.suppliercategoryService.getAssistantmaterialSuppliercategoryByName(suppliercategoryModel.getSupplierCategoryName().trim());
				}
				else if(!suppliercategoryModel.getSupplierCategoryCode().trim().equals("") && !suppliercategoryModel.getSupplierCategoryName().trim().equals("")){
					this.suppliercategoryList = this.suppliercategoryService.getAssistantmaterialSuppliercategoryByCodeAndName(suppliercategoryModel.getSupplierCategoryCode().trim(), suppliercategoryModel.getSupplierCategoryName().trim());
				}
				else {
					this.suppliercategoryList = this.suppliercategoryService.getALLAssistantmaterialSuppliercategory();
				}
			}
		this.suppliercategoryModel= null;
		return "success";
	}
	public String addSuppliercategory() throws Throwable{
		this.suppliercategoryService.addAssistantmatteialSuppliercategory(suppliercategoryModel);
		suppliercategoryModel = null;
		return "success";
	}
	public String showEditSuppliercategory() throws Throwable{
			Integer suppliercategoryId = Integer.valueOf((String) rowlist[0]);
			suppliercategoryModel = suppliercategoryService.getAssistantmaterialSuppliercategoryById(suppliercategoryId);	
		    rowlist = null;
		    return "success";
	}
	public String editSuppliercategory() throws Throwable{
		this.suppliercategoryService.updateAssistantmaterialSuppliercategory(suppliercategoryModel);
		suppliercategoryModel = null;
		return "success";
	}
	public String deleteSuppliercategory() throws Throwable{
	
			suppliercategoryService.deleteAssistantmateialSuppliercategory(rowlist);
			return "success";
	}
	public String selectSuppliercategorySelect() throws Throwable{
		return this.getSuppliercategoryByCondition();
	}
	public PBaseAssistantmaterialSuppliercategory getSuppliercategoryModel() {
		return suppliercategoryModel;
	}
	public void setSuppliercategoryModel(
			PBaseAssistantmaterialSuppliercategory suppliercategoryModel) {
		this.suppliercategoryModel = suppliercategoryModel;
	}
	public Object[] getRowlist() {
		return rowlist;
	}
	public void setRowlist(Object[] rowlist) {
		this.rowlist = rowlist;
	}
	public List<PBaseAssistantmaterialSuppliercategory> getSuppliercategoryList() {
		return suppliercategoryList;
	}
	public void setSuppliercategoryList(
			List<PBaseAssistantmaterialSuppliercategory> suppliercategoryList) {
		this.suppliercategoryList = suppliercategoryList;
	}
	public PBaseAssistantmaterialSuppliercategoryService getSuppliercategoryService() {
		return suppliercategoryService;
	}
	public void setSuppliercategoryService(
			PBaseAssistantmaterialSuppliercategoryService suppliercategoryService) {
		this.suppliercategoryService = suppliercategoryService;
	}
	
}
